<extend name="Public/base"/>

<block name="body">
    <div class="main-title">
        <h2>新增群组</h2>
    </div>
    <notempty name="imgroup" >
        <form action="{:U('Imgroup/editgroup')}" method="post" class="form-horizontal">
            <input type="hidden" name="id" value="{$imgroup.id}" />
            <else />
            <form action="{:U('Imgroup/addgroup')}" method="post" class="form-horizontal">
    </notempty>
    <input type="hidden" name="file_type" id="file_type" value="1"/>
        <div class="form-item">
            <label class="item-label">群组昵称</label>
            <div class="controls">
                <input type="text" class="text input-large" name="nickname" value="{$Imgroup.nickname}">
            </div>
        </div>
    <div class="form-item">
        <label class="item-label">房间ID</label>
        <div class="controls">
            <input type="text" class="text input-large" name="room_id" value="{$Imgroup.room_id}">
        </div>
    </div>
        <div class="form-item">
            <label class="item-label">上传图片</label>
            <div class="controls">
                <div style="float:left;width:100%;" id="imgshow"></div>
                <div style="float: left; height: 30px; width: 800px;">
                    <input type="file" id='upload' style="float:left;" />
                </div>
            </div>
        </div>
        <div class="form-item">
            <input type="hidden" name="avatar_url" id='avatar_url' style="float:left;"  value="{$Imgroup.avatar_url}" />
            <input type="hidden" name="id" style="float:left;"  value="{$id}" />
            <button class="btn submit-btn ajax-post" id="submit" type="submit" target-form="form-horizontal">确 定</button>
            <button class="btn btn-return" onclick="javascript:history.back(-1);return false;">返 回</button>
        </div>
    </form>
</block>

<block name="script">
    <script type="text/javascript" src="__PUBLIC__/static/uploadify/jquery.uploadify.min.js"></script>
    <script src="__STATIC__/thinkbox/jquery.thinkbox.js"></script>
    <script type="text/javascript">
        function previewImage(file,click)
        {
            if(file == ""){
                return;
            }
            $("#imgshow").append('<div class="imgbox"><img class="imghead" width=100 height=100 border=0  style="border:1px solid #139667;" src="'+file+'">' +

                    '</div>');

        }
        var img_pathinfo = "{$Imgroup.avatar_url|default=0}";
        if(img_pathinfo != 0){
            var img_url = "";
            previewImage(img_pathinfo);
        }
        click = 0;
        /* 初始化上传插件 */
        var option = {
            "swf"             : "__STATIC__/uploadify/uploadify.swf",
            "buttonText"      : "{$buttonText|default='上传文件'}",
            "uploader"        : "{:U('File/uploadgood',array('session_id'=>session_id()))}",
            "fileTypeExts"	  : "*.jpg;*.gif;*.png;*.jpeg;",
            "fileSizeLimit"	  : "102400",
            "onUploadStart":function(){
                var formData = $("#upload").uploadify("settings", "formData");
                formData['file_type'] = $("#file_type").val();
                formData['id'] = $("#id").val() ? $("#id").val() : '';
                formData['name'] = $("#name").val() ? $("#name").val() : '';
                $('#upload').uploadify('settings','formData',formData);
            },
            "onUploadSuccess" : function(file,data){

                var data = $.parseJSON(data);
                console.log(data);
                jsonDataDialog(data, {success:function(data){
                    if(data.download.url){
                        previewImage(data.download.url)
                        $("input[name=avatar_url]").val(data.download.url);
                    }
                }});
            },
        };
        upload("#upload", {}, option);
        //导航高亮
        highlight_subnav('{:U('Imgroup/index')}');
    </script>
</block>
